// Copyright 2019 orivil.com. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found at https://mit-license.org.

package code

import (
	"gitee.com/orivil/morgine/xx"
	"gitee.com/tugoer/psy-testing/code/actions"
)

var (
	staticServe        = xx.InitTagName("静态文件服务")
	gameServe          = xx.InitTagName("游戏数据服务")
	sliderServe        = xx.InitTagName("滚动栏数据服务")
	advertisementServe = xx.InitTagName("广告数据服务")
)

var tags = xx.ApiTags{
	{
		Name: staticServe,
	},
	{
		Name: gameServe,
	},
	{
		Name: sliderServe,
	},
	{
		Name: advertisementServe,
	},
}

func registerRoutes() {
	router := xx.Router(tags)
	handleStaticFiles(router.SetTag(staticServe))
	handleGameData(router.SetTag(gameServe))
	handleAdvertisementData(router.SetTag(sliderServe))
	handleSliderData(router.SetTag(advertisementServe))
}

func handleStaticFiles(c *xx.Condition) {
	actions.ServeImage(c)
}

func handleGameData(c *xx.Condition) {
	actions.GetGameData(c)
	actions.GetResultData(c)
	actions.GetSubjectsData(c)
}

func handleAdvertisementData(c *xx.Condition) {
	actions.GetAdvertisements(c)
	actions.SaveAdvertisements(c)
}

func handleSliderData(c *xx.Condition) {
	actions.GetSliders(c)
	actions.SaveSliders(c)
}
